import {INCREAMENT,DECREAMENT} from "./mutation-types"

export const app ={
    state: {
        count:0
      },
      // 实际上是对state做包装处理 | 要return 出去
      getters:{
        myCount(state){
          return `current count is ${state.count}`
        }
      },
      // 方法逻辑写在mutations --改变状态都是在此改变
      mutations: {
        // increament(state,n){
        //   state.count +=n
        // },
        // decreament(state,n){
        //   state.count -=n
        // }
          INCREAMENT(state,n){
            state.count +=n
          },
          DECREAMENT(state,n){
            state.count -=n
          }
      },
      // 业务逻辑写在actions里 (异步函数修改参数)
      actions: {
        async myIncrease(context,obj){
          console.log(obj)
          //...
          context.commit('increament',2)
          context.commit('INCREAMENT',2)
          const products = [1,2,3,4,5] //await axios.get(....);
          return products
        },
        myDecrease(context){
          context.commit('decreament',2)
          context.commit('DECREAMENT',2)
        }
      }
}